﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using db_model;
using MySql.Data.MySqlClient;

namespace db_util {
	public class call_user_util {
		public static call_user_model GetModel(string loginname, string password) {
			var model = new call_user_model();
			string sql = "select id,unique_id,name,loginname,sex,password,e_mail,phone,role_id,last_vis_ip,last_vis_time,create_time,creator,modify_time,modifier,state,is_delete,enable from call_user where loginname=?loginname and password=?password limit 1";
			MySqlParameter[] parameters = {
	 new MySqlParameter("?loginname", MySqlDbType.VarChar,255),
	 new MySqlParameter("?password", MySqlDbType.VarChar,255)
				};
			parameters[0].Value = loginname;
			parameters[1].Value = password;
			using (var dr = mysql_helper.GetDataReader(sql, parameters)) {
				if (dr.Read()) {
					model.id = int.Parse(dr["id"].ToString() == "" ? "-1" : dr["id"].ToString());
					model.unique_id = dr["unique_id"].ToString();
					model.name = dr["name"].ToString();
					model.loginname = dr["loginname"].ToString();
					model.sex = dr["sex"].ToString();
					model.password = dr["password"].ToString();
					model.e_mail = dr["e_mail"].ToString();
					model.phone = dr["phone"].ToString();
					model.role_id = int.Parse(dr["role_id"].ToString() == "" ? "-1" : dr["role_id"].ToString());
					model.last_vis_ip = dr["last_vis_ip"].ToString();
					model.last_vis_time = long.Parse(dr["last_vis_time"].ToString() == "" ? "-1" : dr["last_vis_time"].ToString());
					model.create_time = long.Parse(dr["create_time"].ToString() == "" ? "-1" : dr["create_time"].ToString());
					model.creator = dr["creator"].ToString();
					model.modify_time = long.Parse(dr["modify_time"].ToString() == "" ? "-1" : dr["modify_time"].ToString());
					model.modifier = dr["modifier"].ToString();
					model.state = int.Parse(dr["state"].ToString() == "" ? "-1" : dr["state"].ToString());
					model.is_delete = int.Parse(dr["is_delete"].ToString() == "" ? "-1" : dr["is_delete"].ToString());
					model.enable = int.Parse(dr["enable"].ToString() == "" ? "-1" : dr["enable"].ToString());
				}
			}
			return model;
		}


	}
}
